from typing import List, Optional
from pydantic import BaseModel
from datetime import datetime

class ImageTaskItemBase(BaseModel):
    """图片任务项基础模式"""
    image_url: str
    original_filename: Optional[str] = None
    file_size: Optional[int] = None
    file_type: Optional[str] = None
    width: Optional[int] = None
    height: Optional[int] = None
    sort_order: int = 0

class ImageTaskItemCreate(ImageTaskItemBase):
    """创建图片任务项"""
    pass

class ImageTaskItemResponse(ImageTaskItemBase):
    """图片任务项响应 - 简化版"""
    id: int
    task_id: int
    upload_status: str
    created_at: datetime
    # 移除不需要的字段：cos_url, cos_key, file_size, file_type等
    
    class Config:
        from_attributes = True

class ImageTaskBase(BaseModel):
    """图片任务基础模式"""
    task_name: str
    description: Optional[str] = None

class ImageTaskCreate(ImageTaskBase):
    """创建图片任务"""
    image_urls: Optional[List[str]] = []

class ImageTaskUpdate(BaseModel):
    """更新图片任务"""
    task_name: Optional[str] = None
    description: Optional[str] = None
    is_active: Optional[bool] = None

class ImageTaskResponse(ImageTaskBase):
    """图片任务响应"""
    id: int
    user_id: int
    is_active: bool
    image_count: int
    created_at: datetime
    updated_at: datetime
    images: List[ImageTaskItemResponse] = []
    
    class Config:
        from_attributes = True

class ImageTaskListResponse(BaseModel):
    """图片任务列表响应"""
    id: int
    task_name: str
    description: Optional[str] = None
    is_active: bool
    image_count: int
    created_at: datetime
    updated_at: datetime
    
    class Config:
        from_attributes = True

# 批量上传请求
class BatchImageUploadRequest(BaseModel):
    """批量图片上传请求"""
    task_id: Optional[int] = None  # 如果为None则创建新任务
    task_name: Optional[str] = None  # 新任务名称
    description: Optional[str] = None
    # 移除 image_urls 字段，改为在接口中直接接收文件

class BatchImageUploadResponse(BaseModel):
    """批量图片上传响应"""
    code: int
    msg: str
    data: dict